package com.fish.admin.module.tenant.manager;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.fish.admin.module.system.domain.entity.SysRole;
import com.fish.admin.module.tenant.domain.bo.TenantInfoBO;
import com.fish.admin.module.tenant.domain.dto.TenantInfoPageQueryDTO;
import com.fish.admin.module.tenant.domain.entity.TenantInfo;
import com.fish.admin.module.tenant.mapper.TenantInfoMapper;
import com.fish.common.mybatisplus.util.PageUtils;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

@RequiredArgsConstructor
@Component
public class TenantInfoManager {

    private final TenantInfoMapper tenantInfoMapper;

    public void save(TenantInfo TenantInfo){
        tenantInfoMapper.insert(TenantInfo);
    }

    public void deleteById(Long id){
        tenantInfoMapper.deleteById(id);
    }

    public void updateById(TenantInfo TenantInfo){
        tenantInfoMapper.updateById(TenantInfo);
    }


    public TenantInfo getById(Long id){
        return tenantInfoMapper.selectById(id);
    }

    public IPage<TenantInfoBO> page(TenantInfoPageQueryDTO pageQuery) {
        MPJLambdaWrapper<TenantInfo> wrapper = new MPJLambdaWrapper<TenantInfo>()
                .selectAll(TenantInfo.class)
                .selectAs(SysRole::getName, TenantInfoBO::getRoleName)
                .selectAs(SysRole::getId, TenantInfoBO::getRoleId)
                .leftJoin(SysRole.class, on->on.eq(TenantInfo::getRoleId, SysRole::getId))
                .likeIfExists(TenantInfo::getTenantNo, pageQuery.getTenantNo())
                .likeIfExists(TenantInfo::getAccount, pageQuery.getAccount());
        return tenantInfoMapper.selectJoinPage(PageUtils.build(pageQuery),  TenantInfoBO.class,wrapper);





    }





}
